package cn.btks.databasehandler.basic.controller;

import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.databasehandler.basic.pojo.DBBasic;
import cn.btks.databasehandler.basic.service.DBBasicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author lijun
 * @Date 2020/12/30 17:17
 */
@RestController
@RequestMapping("api/v1.0/backUpConfig")
@Api(tags = "备份配置模块")
@Validated
public class DBBasicController {

    @Autowired
    DBBasicService dbBasicService;

    @GetMapping("/findPages/findAll")
    @ApiOperation("查询所有数据库字典基础数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAll() {
        List<DBBasic> dbBasicList = dbBasicService.findAll();
        return dbBasicList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), dbBasicList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/findPages/findAllByIsDB/{isDB}")
    @ApiOperation("根据是否数据库查询字典基础数据")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "isDB", value = "是否数据库还是数据表（0：数据表 1：数据库）", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAllByIsDB(@PathVariable("isDB") Integer isDB) {
        List<DBBasic> dbBasicList = dbBasicService.findByIsDB(isDB);
        return dbBasicList != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), dbBasicList) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }
}
